package com.example.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.example.demo.entity.Banners;
import com.example.demo.service.IBannersService;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PassToken;
import com.example.demo.utils.ResponseResult;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * bannersController
 * 
 * @author ruoyi
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/system/banners")
public class BannersController
{
    @Autowired
    private IBannersService bannersService;

    /**
     * 查询banners列表
     */
    @PassToken
    @GetMapping("/list")
    public ResponseResult list(Banners banners, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "3")  int pageSize)
    {
        System.out.println("sdfsdf");
        PageResult pageResult = bannersService.selectBannersList(banners,pageNum,pageSize);

        return ResponseResult.createBySuccess(200,pageResult,"获取成功");
    }

    /**
     * 获取banners详细信息
     */
    @GetMapping(value = "/{id}")
    public ResponseResult getInfo(@PathVariable("id") Long id)
    {
        return ResponseResult.createBySuccess(200,bannersService.selectBannersById(id),"获取成功");
    }

    /**
     * 新增banners
     */
    @PostMapping
    public ResponseResult add(@RequestBody Banners banners)   {
        int i = bannersService.insertBanners(banners);
        if(i>0){
           return ResponseResult.createBySuccess(200,"","添加成功");
        }else{
            return  ResponseResult.createByFail(500,"添加失败");

        }

    }
    /**
     * 修改banners
     */
    @PutMapping
    public ResponseResult edit(@RequestBody Banners banners)
    {
        int i = bannersService.updateBanners(banners);
        if(i>0){
            return ResponseResult.createBySuccess(200,"","添加成功");
        }else{
            return  ResponseResult.createByFail(500,"添加失败");

        }
    }

    /**
     * 删除banners
     */
	@DeleteMapping("/{ids}")
    public ResponseResult remove(@PathVariable Long[] ids)
    { int i = bannersService.deleteBannersByIds(ids);
        if(i>0){
            return ResponseResult.createBySuccess(200,"","删除成功");
        }else{
            return  ResponseResult.createByFail(500,"删除失败");

        }

    }
}
